package gui;

import java.awt.BorderLayout;

import java.awt.EventQueue;
import java.awt.Rectangle;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import user.User;
import java.awt.GridLayout;

import types.DEPT_TYPES;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.ListSelectionModel;

import java.awt.FlowLayout;
import java.awt.Component;
import javax.swing.Box;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class StudentDeptSelect extends JFrame {

	private JPanel contentPane;
	
	private User currUser;

	private JList deptList;

	private JScrollPane deptScrollPane;
	private JPanel panel;
	private JPanel panel_5;
	private JPanel panel_4;
	private JLabel currentTermLabel;
	private JPanel panel_1;
	private JPanel panel_2;
	private JPanel panel_3;
	private JSplitPane splitPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StudentDeptSelect frame = new StudentDeptSelect(new User("stud1"));
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public StudentDeptSelect(User currUser) {
		this.currUser = currUser;
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		
		panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(new GridLayout(3, 1, 0, 0));
		
		panel_5 = new JPanel();
		panel.add(panel_5);		
			
		JLabel lblCurrentTerm_1 = new JLabel("Current Term: ");
		panel_5.add(lblCurrentTerm_1);
		
		panel_4 = new JPanel();
		panel.add(panel_4);
		
		currentTermLabel = new JLabel("Department: ");
		panel_4.add(currentTermLabel);
		currentTermLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);
		
		deptList = new JList(new DefaultComboBoxModel(DEPT_TYPES.values()));
		deptList.setBounds(new Rectangle(0, 0, 0, 10));
		deptList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		deptList.setSelectedIndex(1);
		deptList.setDoubleBuffered(true);
		deptList.setVisibleRowCount(3);
		deptList.setSelectedIndex(0);
		
		deptScrollPane = new JScrollPane(deptList);
		panel_4.add(deptScrollPane);
		
		panel_1 = new JPanel();
		contentPane.add(panel_1, BorderLayout.NORTH);
		
		panel_2 = new JPanel();
		contentPane.add(panel_2, BorderLayout.EAST);
		
		panel_3 = new JPanel();
		contentPane.add(panel_3, BorderLayout.WEST);
		
		splitPane = new JSplitPane();
		contentPane.add(splitPane, BorderLayout.SOUTH);
		
		JButton btnNext = new JButton("Next");
		splitPane.setRightComponent(btnNext);
		btnNext.addActionListener(nextListener);
		
		JButton btnBack = new JButton("Back");
		splitPane.setLeftComponent(btnBack);
		btnBack.addActionListener(cancelListener);
	}
	
	private ActionListener nextListener = new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent arg0) {
			StudentCourseSelect regFrame = new StudentCourseSelect(currUser, (DEPT_TYPES) deptList.getSelectedValue());
			regFrame.setVisible(true);
			StudentDeptSelect.this.dispose();
		}
	};
	
	private ActionListener cancelListener = new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent arg0) {
			ServiceFrame regFrame = new ServiceFrame(currUser);
			regFrame.setVisible(true);
			StudentDeptSelect.this.dispose();
		}
	};
}
